<?php
namespace Admin\Controller;
use Think\Controller;
class HomController extends Controller {

	//分类展示
	public function type(){

		$type = M('game_type');

		$total = $type->count();

		$result = $type->order('rank desc')->select();

		if($result !== false){

            $data['page']['total_page'] = $total;
            $data['list'] = $result;
            

            $ajaxReturn['code'] = 1;
            $ajaxReturn['msg'] = "SUCCESS";
            $ajaxReturn['data'] = $data;
        }else{

            $ajaxReturn['code'] = 2;
            $ajaxReturn['msg'] = "数据查询失败！";
        }

        $this->ajaxReturn($ajaxReturn);

	}

	//公告列表展示
	public function notice(){

		$notice = M('notice');

		$result = $notice->Getfield('id,login_time,title');

		$array = array_merge($result);

		foreach($array as $key=>$v){
			$data[$key]['time'] = date('m/d H:i',$v['login_time']);
			$data[$key]['title'] = $v['title'];
			$data[$key]['id'] = $v['id'];
		}

		$this->assign('data',$data);
		$this->display();

	}

	//公告详情
	public function notice_details(){

		$id = I('get.id');

		$notice = M('notice');

		$result = $notice->where('id='.$id)->find();

		$titlea =  explode(';',$result['titlea']);
		$content = explode(';',$result['content']);
		
		$data['titlea'] = $titlea;
		$data['content'] = $content;
		$data['title'] = $result['title'];
		$data['login_time'] = $result['login_time'];
		$data['id'] = $id;

		$this->assign('data',$data);
		$this->display();

	}

	//我的列表
	public function mine(){

		$openid = I('post.openid');

		$game = M('game');

		$result = $game->where('openid='.$openid)->find();

		$this->assign('data',$result);
		
		$this->display();

	}

	//我的列表详情
	public function mine_details(){

		$head = I('post.head');
		$nickname = I('post.nickname');
		$old = I('post.old');
		$gender = I('post.gender');
		$birthday = I('post.birthday');
		$phone = I('post.phone');

		$data['head'] = $head;
		$data['nickname'] = $nickname;
		$data['old'] = $old;
		$data['gender'] = $gender;
		$data['birthday'] = $birthday;
		$data['phone'] = $phone;

		$game = M('game');

		$result = $game->add($data);

		if($result!=false){

			$ajaxReturn['code'] = 1;
			$ajaxReturn['msg'] = '添加成功！';

		}else{

			$ajaxReturn['code'] = 2;
			$ajaxReturn['msg'] = "添加失败！";

		}

		$this->ajaxReturn($ajaxReturn);

	}

}